#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int n = 0;
    int arr[1000] = { 0 };
    scanf("%d", &n);
    for (int i = 0;i < n;i++)
    {
        scanf("%d", &arr[i]);
    }
    int tmp = 0;
    int count = 0;
    for (int i = 0;i < n;i++)
    {
        if (count == 0)
        {
            tmp = arr[i];
            count++;
        }
        else if (arr[i] == tmp)
        {
            count++;
        }
        else
        {
            count--;
            if (count == 0)
            {
                tmp = arr[i];
                count++;
            }
        }
    }
    printf("%d",tmp);
    return 0;
}